﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;

namespace FixICal
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
             Application.ItemLoad += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
        }

        Outlook.MeetingItem meeting;
        Outlook.AppointmentItem appoitment;
        void Application_ItemLoad(object Item)
        {
            if (Item is Outlook.MeetingItem)
            {

                meeting = Item as Outlook.MeetingItem;
                meeting.Read+=new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReadEventHandler(meeting_Read);
            }

            if (Item is Outlook.AppointmentItem)
            {

                appoitment = Item as Outlook.AppointmentItem;
                appoitment.Read+=new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReadEventHandler(appoitment_Read);
            }
          
        }

        void  meeting_Read()
        {
 	        try
            {
                meeting.Body = meeting.Body.Replace("&rlm;", "").Replace("&lrm;", "");
            }
            catch (Exception ex)
            {
            }
        }

        void appoitment_Read()
        {
            try
            {
                appoitment.Body = appoitment.Body.Replace("&rlm;", "").Replace("&lrm;", "");
            }
            catch (Exception ex)
            {
            }
        }
            
  

       

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            meeting = null;
            appoitment = null;
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            
        }
        
        #endregion
    }
}
